package com.sumer.jvolatile;


import java.util.concurrent.TimeUnit;

public class JMMTest {

    // 不加volatile关键字，子线程就会死循环
    private volatile static Integer num = 0;

    public static void main(String[] args) {
        new Thread(()->{
            // 线程一对主存的变化不知道
            while (num == 0){
            }
        }).start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        num = 1;
        System.out.println(num);
    }

}
